<!--
 * @Autor: Haiting Zhao
 * @Date: 2022-02-26 14:42:26
 * @LastEditors: Haiting Zhao
 * @LastEditTime: 2022-04-05 21:32:28
 * @Description: file content
 * @FilePath: \league_and_student_organization_management_system_font\src\views\Login.vue
-->
<template>
  <div class="Logina">
    <div id="nav">
      <router-link to="/Login">Login</router-link>
      <a href="#">|</a>
      <router-link to="/">Home</router-link>
    </div>
    <div class="box"></div>
    <!-- 空盒 -->
    <div class="header">
      <!-- log -->
      <div class="header-img">
        <img src="./../assets/img/jk.png" alt />
      </div>
    </div>
    <!-- 登录部分 -->
    <div class="login">
      <div class="login-form">
        <form>
          <div class="form-tabs">
            <div class="tabs-left">密码登录</div>
          </div>

          <div class="form-account">
            <div class="form-account-right">
              <input type="text" v-model="username" placeholder="用户名" />
            </div>
          </div>
          <div class="form-password">
            <input type="password" v-model="password" name id placeholder="密码" />
          </div>
          <div class="form-verify">
            <input type="text" v-model="verification" placeholder="图形验证码" />
            <a href="javascript:;" @click="changeCodeImg()">
              <img :src="codeimageurl" />
            </a>
          </div>
          <div class="login-options">
            <!-- 邮箱账号忘记密码 -->
            <button class="login-options-left">邮箱账号登录</button>
            <button class="login-options-right">忘记密码</button>
          </div>
        </form>
          <button @click="userlogin()" class="enter">登录</button>
      </div>
    </div>
    <!-- 结尾footer -->
    <!-- <div class="footer">
      <div class="footer-a">下载知乎App知乎专栏圆桌发现移动应用联系我们来知乎工作注册机构号</div>
      <div
        class="footer-b"
      >© 2020 知乎京 ICP 证 110745 号京 ICP 备 13052560 号 - 1京公网安备 11010802010035 号出版物经营许可证</div>
      <div class="footer-c">侵权举报网上有害信息举报专区儿童色情信息举报专区违法和不良信息举报：010-82716601</div>
    </div>-->
  </div>
</template>
<script>
import axios from 'axios'
import crypto from '../crypto/index'
import qs from 'qs'
export default {
  name: 'Login',
  data () {
    return {
      code: '',
      username: '',
      password: '',
      verification: '',
      isBtnLoading: false,
      codeimageurl: '',
      rules: {
        // tigger表示鼠标移出时验证，通过prop绑定
        // 用户名是否合法
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
        ],
        // 密码是否合法
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
          // {min: 5, max: 15, message: "长度在 5 到 15 个字符", trigger: "blur"},
        ],
        //  图片验证码
        verification: [
          { required: true, message: '请输入图形验证码', trigger: 'blur' }
        ]
      }
    }
  },
  created () {
    this.changeCodeImg()
  },
  computed: {
  },
  methods: {
    changeCodeImg () {
      axios.get('/captcha',
        {
          responseType: 'blob'
        })
        .then(res => {
          console.log(res.data)
          const blob = new Blob([res.data], { type: 'image/jpeg' })
          this.codeimageurl = window.URL.createObjectURL(blob)
        }).catch(res => {
          return this.$message.error('验证码图片获取失败!')
        })
    },
    async userlogin () {
      console.log(this.username)
      await axios
        .post('/login',
          qs.stringify({
            sid: this.username,
            password: this.password,
            code: this.verification
          }), {
            headers: {
              'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
            },
            crossDomain: true
          }
        )
        .then((res) => {
          if (res.data.code === 200) {
            console.log('loginRes', res.data)
            this.$router.push('/' + crypto.set('2'))
          } else {
            this.$message.info(res.data.message)
            this.changeCodeImg()
          }
        })
        .catch((err) => {
          console.log(err)
          this.changeCodeImg()
        })
    }
  }
}
</script>
<style>
.Logina {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  background: url(../assets/img/16.jpg) no-repeat; /*背景图不重复*/
  background-size: cover;
  background-size: 100%;
}
.box {
  height: 60px;
}
.header {
  height: 100px;
}
.header-img {
  width: 128px;
  height: 81px;
  margin: 0 auto;
}
.header img {
  width: 128px;
  height: 81px;
}
/*  */
.login-form {
  width: 400px;
  height: 376px;
  background: rgba(255, 255, 255, 0.586);
  margin: 0 auto;
  padding: 0 24px 84px 24px;
}
.form-tabs {
  width: 352px;
  height: 60px;
  margin: 0 auto;
  font-size: 16px;
  text-align: center;
}
.form-tabs .tabs-left {
  width: 80px;
  height: 60px;
  /* float: left; */
  /* margin-right: 24px; */
  margin: 0 auto;
  display: inline-block;
  line-height: 60px;
}
.form-tabs .tabs-right {
  width: 64px;
  height: 60px;
  /* float: left; */
  margin-right: 24px;
  display: inline-block;
  line-height: 60px;
}
.form-account {
  width: 352px;
  height: 49px;
  margin: 0 auto;
  margin-top: 24px;
}
.form-account .form-account-left {
  width: 92px;
  height: 26px;
  float: left;
}
.form-account .form-account-right {
  width: 352px;
  margin: 0 auto;
  height: 48px;
  /* float: left; */
}
.form-account .form-account-right input {
  width: 352px;
  height: 48px;
  border: none;
  border-bottom: 1px solid #8590a6;
  background: rgba(255, 255, 255, 0.586);
}
.form-password {
  margin: 0 auto;
  margin-top: 10px;
  width: 352px;
  height: 48px;
}
.form-password input {
  width: 352px;
  height: 48px;
  border: none;
  border-bottom: 1px solid #8590a6;
  background: rgba(255, 255, 255, 0.586);
}
.form-verify {
  margin: 0 auto;
  margin-top: 10px;
  width: 352px;
  height: 48px;
}
.form-verify input {
  width: 230px;
  height: 48px;
  border: none;
  border-bottom: 1px solid #8590a6;
  float: left;
  background: rgba(255, 255, 255, 0.586);
}
.form-verify a {
  width: 100px;
  height: 48px;
  float: right;
}
.form-verify a img {
  width: 100%;
  height: 100%;
}
/*  */
.login-options {
  margin: 0 auto;
  width: 352px;
  height: 20px;
  margin-top: 12px;
}
.login-options .login-options-left {
  float: left;
  width: 84px;
  color: #175199;
  font-size: 14px;
  border: none;
  padding: 0;
  line-height: inherit;
  background-color: transparent;
}
.login-options .login-options-right {
  float: right;
  width: 74px;
  padding: 0;
  line-height: inherit;
  background-color: transparent;
  border: none;
  border-radius: 0;
}
/* 登录按钮 */
.enter {
  width: 352px;
  height: 40px;
  font-size: 17px;
  background-color:#66c6f1;
  border-radius: 8px;
  border: none;
  /* border-color: #66c6f1; */
  color: #fff;
  margin-top: 25px;
}
.form-tip {
  width: 400px;
  height: 57px;
  font-size: 13px;
  color: grey;
  padding: 12px 24px;
}
/*  */
.social {
  width: 400px;
  height: 60px;
  padding: 0 24px;
}
/* 开通机构 */
.pky {
  width: 400px;
  height: 60px;
  padding: 0 24px;
}
.pky .pky-left {
  width: 50%;
  float: left;
}
.pky .pky-right {
  width: 50%;
  float: left;
}
/* 结尾 */
.footer {
  height: 88px;
  font-size: 12px;
  text-align: center;
}
</style>
